// pages/danger/index.js
//获取应用实例
const app = getApp()
const host = app.globalData.host
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageInfo:[],
    index:1
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    var token = wx.getStorageSync('token');
    wx.showLoading({
      title: '加载中',
    })
    console.log(token);
    //主页内容
    wx.request({
      url: host + '/risk/maincates',
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        token: token
      },
      success(res) {
        wx.hideLoading()
        console.log(res.data);
        if (res.data.code == 0) {
          that.setData({
            pageInfo: res.data.data
          })
        } else if(res.data.code == 4104){
          wx.setStorageSync("token", "")
          
        }else{
          app.globalData.isShow(res.data.msg)
        }

      },
      fail(res) {
        app.globalData.isShow(res.data.msg);
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
 
  onShow: function () {
    var that = this
    
    
    // 检测是否登录
    app.globalData.isLog();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
 clear(){
   var that = this;
   console.log(12);
   that.data.index++;
   if(that.data.index <3){
     wx.request({
       url: host + '/users/clear',
       method: 'GET',
       header: {
         'content-type': 'application/x-www-form-urlencoded'
       },
       success(res) {
         console.log(res);
       }
     })
   }
   
 }
})